package com.zhibang.controller;

import com.zhibang.util.OSSImageUploader;
import com.zhibang.util.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class UploadController {

    @PostMapping("upload")
    public Result upload(MultipartFile file) throws IOException {
        try {
            String imgUrl = OSSImageUploader.uploadImage(
                    file.getInputStream(),
                    file.getOriginalFilename(),
                    "img/");
            return Result.ok("上传成功",imgUrl);
        } catch (IOException e) {
            return Result.ok("上传失败");
        }
    }
}
